package com.newsReader.category.model;

import java.util.List;

import com.eova.common.base.BaseModel;
import com.jfinal.plugin.activerecord.Db;

public class Category extends BaseModel<Category>{
	
	/**
	 * TODO（用一句话描述这个变量表示什么）
	 */

	private static final long serialVersionUID = 1L;
	
	
	public static final Category dao = new Category();
	/**
	 * 栏目列表
	 * @param 
	 * @return
	 */
	public List<Category> findCategoryList() {
		String sql = "select id,title,content,imgurl,createDate,`status`,ord from c_category WHERE STATUS=1";
		return this.find(sql);
	}
	
	//栏目详情
	public Category columnDetail(int id) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT id,title,content,imgUrl,createDate FROM c_category where id=?");
		return this.findFirst(sql.toString(),id);
	}
	
	
	//我的栏目
	public List<Category> Mycate(int userId){
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT cate.id caId,title,cus.userId,cus.style FROM");
		sql.append(" c_category cate LEFT JOIN (SELECT id,userId,cateId,style from n_cateUser  WHERE userId=?)cus ON cate.id=cus.cateId ");
		return this.find(sql.toString(),userId);
	}
	
	//新增我的栏目int userId,int cateId
	public int addMycate(int userId,int cateId){
		StringBuffer sql = new StringBuffer();
		sql.append("UPDATE n_cateUser SET style='' WHERE cateId=? and userId=?");
		return Db.update(sql.toString(),cateId,userId);
	}
	//删除我的栏目
	public int delMycate(int userId,int cateId){
		StringBuffer sql = new StringBuffer();
		sql.append("UPDATE n_cateUser SET style='active' WHERE cateId=? and userId=?");
		return Db.update(sql.toString(), cateId,userId);
	}

}